package services

import (
	"jlpay-sdk-go/pkg/jlpay/core"
	"jlpay-sdk-go/pkg/jlpay/models"
)

// CashierService 收银台服务类
type CashierService struct {
	*BaseService
}

// NewCashierService 创建收银台服务
func NewCashierService(config *core.Config) *CashierService {
	return &CashierService{
		BaseService: NewBaseService(config),
	}
}

// QueryOrder 查询订单状态
func (s *CashierService) QueryOrder(request *models.OrderQueryRequest) (*models.OrderQueryResponse, error) {
	response := models.NewOrderQueryResponse()

	// 设置API路径
	apiPath := "/open/cashier/trans/trade/query"

	// 发送请求
	err := s.Post(request, response, apiPath)
	if err != nil {
		return nil, err
	}

	return response, nil
}

// CreatePreOrder 创建预下单
func (s *CashierService) CreatePreOrder(request *models.PreOrderRequest) (*models.PreOrderResponse, error) {
	response := models.NewPreOrderResponse()

	// 设置API路径
	apiPath := "/open/cashier/trans/trade/pre-order"

	// 发送请求
	err := s.Post(request, response, apiPath)
	if err != nil {
		return nil, err
	}

	return response, nil
}

// CancelTrade 撤销交易
func (s *CashierService) CancelTrade(request *models.TradeCancelRequest) (*models.TradeCancelResponse, error) {
	response := models.NewTradeCancelResponse()

	// 设置API路径
	apiPath := "/open/cashier/trans/trade/cancel"

	// 发送请求
	err := s.Post(request, response, apiPath)
	if err != nil {
		return nil, err
	}

	return response, nil
}

// RefundTrade 退款交易
func (s *CashierService) RefundTrade(request *models.TradeRefundRequest) (*models.TradeRefundResponse, error) {
	response := models.NewTradeRefundResponse()

	// 设置API路径
	apiPath := "/open/cashier/trans/trade/refund"

	// 发送请求
	err := s.Post(request, response, apiPath)
	if err != nil {
		return nil, err
	}

	return response, nil
}
